from IPython.display import HTML
HTML('''<script>
code_show=true;
function code_toggle() {
if (code_show){
$('div.input').hide();
} else {
$('div.input').show();
}
code_show = !code_show
}
$( document ).ready(code_toggle);
</script>
<form action="javascript:code_toggle()"><input type="submit" value="Magic Button."></form>''')
from plotly import graph_objs as go
from plotly.offline import iplot, init_notebook_mode
import numpy as np
init_notebook_mode()
def plot_multiple(Xs,Ys):
assert len(Xs) == len(Ys)
traces = [go.Scatter(x=Xs[i], y = Ys[i], mode = 'lines') for i in range(len(Xs))]
iplot(traces)
def plotit(x,y):
trace1 = go.Scatter(x = x, y = y , mode='lines', name = 'f(x)')
iplot([trace1])
$$ f(x) = 3^x$$ $$ g(x) = (1/2)^x$$ $$ h(x) = (4/3)^x$$
Exponential functions with base >1 get very big very quickly for large inputs, and get very small very quickly on small inputs.
$$ y = 3^x$$
| x | y |
|---|---|
| -3 | $3^{-3}$ |
| -2 | $3^{-2}$ |
| -1 | $3^{-1}$ |
| 0 | $3^{0}$ |
| 1 | $3^{1}$ |
| 2 | $3^{2}$ |
| 3 | $3^{3}$ |
| x | y |
|---|---|
| -3 | $1/27$ |
| -2 | $1/9$ |
| -1 | $1/3$ |
| 0 | $1$ |
| 1 | $3$ |
| 2 | $9$ |
| 3 | $27$ |
| 4 | 81 |
| 5 | 243 |
x = np.arange(-5,5,.1)
y = 3**x
plotit(x,y)
Brandon invests €10000 into his retirement account. Every year, his account grows by 6%
Let $m$ be Brandon's money, and $t$ be the number of years he has been invested for.
$$m(t) = 10000(1.06)^t$$
Fun fact:
In the real world, many financial investments do not exactly follow an exponential formula. Instead, they are stochastic processes. This means that their growth every year is random. However, over time, their growth pattern looks exponential. Other investments, like government bonds, grow exponentially.
x = np.arange(0,50,1)
y = 10000 * (1 + .06)**x
plotit(x,y)

Jane also invests €10000 into her retirement account. Sadly for her, every year, her account shrinks by 6%
Let $m$ be Jane's money, and $t$ be the number of years she has been invested for.
$$m(t) = 10000(1-.06)^t = 10000*.94^t$$
x = np.arange(0,40,1)
y1 =10000* 1.06**x
y2= 10000*.94**x
plot_multiple([x,x],[y1,y2])
Recall that logarithms are the inverse of exponents.
$$log_b(x) = y \iff b^y = x$$
import math
vlog = np.vectorize(math.log)
x = np.arange(1,100,.1)
y1 = vlog(x,2)
y2 = vlog(x,3)
#x.apply
trace0 = go.Scatter(x=x, y=vlog(x,2), mode = 'lines', name = '$f(x)=log_2(x)$')
trace1 = go.Scatter(x=x, y=y2, mode = 'lines', name = '$f(x)=log_3(x)$')
trace2 = go.Scatter(x=x, y=vlog(x,4), mode = 'lines', name = '$f(x)=log_4(x)$')
traces = [trace0,trace1,trace2]
iplot(traces)
import math
vlog = np.vectorize(math.log)
x1 = np.arange(.0001,4,.0001)
x2 = np.arange(-5,4,.1)
y1 = vlog(x1,2)
y2 = 2**x2
#x.apply
trace0 = go.Scatter(x=x1, y=y1, mode = 'lines', name = '$f(x)=log_2(x)$')
trace1 = go.Scatter(x=x2, y=y2, mode = 'lines', name = '$f(x)=2^x$')
#trace2 = go.Scatter(x=x, y=vlog(x,4), mode = 'lines', name = '$f(x)=log_4(x)$')
traces = [trace0,trace1]#,trace2]
iplot(traces)
$$\text{log}_2(1/8)$$
$$\text{log}_3(27)$$
$$\text{log}_{10}(\frac{1}{100})$$
$$f(x) = \text{log}_2(x)$$
Domain : $x > 0$
Range : all real numbers
The domain and range of exponents and logarithms are opposite.